%% Carbon Taxes Around the World: Cooperation, Strategic Interactions, and Spillovers
% IMF Economic Review
% Alessandro Moro and Valerio Nispi Landi
% Replication files
% This file sets the function to compute the final steady state

function [ F ]  = find_steady_final(x, gamma,gammaz,eta,beta,betaz,alpha1,alpha2,alpha1z,alpha2z,chi,...
      GAM,GAMz,n,delta,iota,zeta,csi,kappaA,mu,muz,nu,tau,tauz,A,r,rz,v,g,gz,Az,zetae,zetaez,kappaAz)
yH=x(1);
pH=x(2);
pB=x(3);
pBz=x(4);
yFz=x(5);

pF=((1-(1-gamma)*pH^(1-eta))/gamma)^(1/(1-eta));
s=(gammaz*pH^(1-eta)+(1-gammaz)*pF^(1-eta))^(1/(1-eta));
dH=(1-beta/betaz)/GAM;
dF=s/GAMz*(betaz/beta-1);
b=-(v+dH+dF*(1-n)/n);
gdp=pH*yH;
rkB=iota/beta-(1-delta);            
rkB_zd=iota/beta-(1-delta);         
rkB_zu=iota/betaz-(1-delta);       
rkB_zz=iota/betaz-(1-delta);      
rkG=iota/beta-(1-delta);            
rkG_zz=iota/betaz-(1-delta);       
rkG_zd=iota/beta-(1-delta);         
rkG_zu=iota/betaz-(1-delta);       
yB=zeta*(pB/pH)^(-csi)*yH;
pB2= pB- tau *(1-mu) *zetae-kappaA/(1+nu)*mu^(1+nu);
pB2z=pBz-tauz*(1-muz)*zetaez-kappaAz/(1+nu)*muz^(1+nu);
pGY=pH*yH-pB*yB;
kB=alpha1*iota/rkB*pB2*yB;
kG=alpha1*iota/rkG*pGY;
i=(kB+kG)*(1-(1-delta)/iota);
kB_zu=alpha2*iota/rkB_zu*pB2*yB;
kG_zu=alpha2*iota/rkG_zu*pGY;
i_zu=(kB_zu+kG_zu)*(1-(1-delta)/iota);
hB=(yB/(A*(kB/iota)^alpha1*(kB_zu/iota)^alpha2))^(1/(1-alpha1-alpha2));
w=(1-alpha1-alpha2)*pB2*yB/hB;
hG=(1-alpha1-alpha2)*pGY/w;
h=hG+hB;
yG=A*(kG/iota)^alpha1*(kG_zu/iota)^alpha2*(hG)^(1-alpha1-alpha2);
pG=pGY/yG;
yBz=zeta*(s*pBz/pF)^(-csi)*yFz;
gdpz=pF*yFz/s;
pGYz=gdpz-pBz*yBz;
kB_zz=alpha1z*iota*pB2z*yBz/rkB_zz;
kG_zz=alpha1z*iota*pGYz/rkG_zz;
kB_zd=alpha2z*iota*pB2z*yBz/rkB_zd;
kG_zd=alpha2z*iota*pGYz/rkG_zd;
i_zd=(kB_zd+kG_zd)*(1-(1-delta)/iota);
i_zz=(kB_zz+kG_zz)*(1-(1-delta)/iota);
c=-(i+pH*g+kappaA/(1+nu)*mu^(1+nu)*yB+b+(1-n)/n*s*i_zd-s*(1-n)/n*(rkB_zd*kB_zd    +rkG_zd*kG_zd)    /iota+(rkB_zu*kB_zu    +rkG_zu*kG_zu)    /iota+rz            *(dH+v)    /iota-r/iota    *(b+    dH    +v)-gdp);
cz=n/((1-n)*gammaz)*(pH/s)^(eta)*(yH-((1-gamma)*pH^(-eta)*(c+i+kappaA/(1+nu)*mu^(1+nu)*yB+i_zu)+g))-(i_zz+i_zd+kappaAz/(1+nu)*muz^(1+nu)*yBz);
wz=(cz^(1/chi)*(1-alpha1z-alpha2z)*(pB2z*yBz+pGYz))^(chi/(1+chi));
hz=(wz/cz)^(1/chi);
hBz=(1-alpha1z-alpha2z)*pB2z*yBz/wz;
hGz=hz-hBz;
yGz=Az*(kG_zz/iota)^alpha1z*(kG_zd/iota)^alpha2z*(hGz)^(1-alpha1z-alpha2z);
pGz=pGYz/yGz;
  


F=[h^(chi)*c-w
    (1-n)*((1-gammaz)*(pF/s)^(-eta)*(cz+i_zz+i_zd+kappaAz/(1+nu)*muz^(1+nu)*yBz)+gz)+n*(gamma*(pF^(-eta))*(c+i+i_zu+kappaA/(1+nu)*mu^(1+nu)*yB))-(1-n)*yFz
    yGz-(1-zeta)*(s*pGz/pF)^(-csi)*yFz
    yG-(1-zeta)*(pG/pH)^(-csi)*yH
    Az-yBz/((kB_zz/iota)^alpha1z*(kB_zd/iota)^alpha2z*(hBz)^(1-alpha1z-alpha2z))
    ];
end